﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x0200031F RID: 799
	public class VillageNeedsToolsIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002DF3 RID: 11763 RVA: 0x000C0DDD File Offset: 0x000BEFDD
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002DF4 RID: 11764 RVA: 0x000C0DF8 File Offset: 0x000BEFF8
		private void OnCheckForIssue(Hero hero)
		{
			ItemObject tools = DefaultItems.Tools;
			if (this.ConditionsHold(hero, tools))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof(VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue), IssueBase.IssueFrequency.VeryCommon, tools));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002DF5 RID: 11765 RVA: 0x000C0E64 File Offset: 0x000BF064
		private bool ConditionsHold(Hero issueGiver, ItemObject item)
		{
			Settlement currentSettlement = issueGiver.CurrentSettlement;
			if (issueGiver.IsHeadman && currentSettlement != null && currentSettlement.IsVillage && currentSettlement.Village.GetProsperityLevel() < SettlementComponent.ProsperityLevel.Mid && currentSettlement.Village.VillageType.Productions.Count > 0)
			{
				if (currentSettlement.Village.VillageType.Productions.All((ValueTuple<ItemObject, float> x) => !x.Item1.IsAnimal))
				{
					return currentSettlement.ItemRoster.GetItemNumber(item) == 0;
				}
			}
			return false;
		}

		// Token: 0x06002DF6 RID: 11766 RVA: 0x000C0EF8 File Offset: 0x000BF0F8
		private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
		{
			PotentialIssueData potentialIssueData = pid;
			return new VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue(issueOwner, (ItemObject)potentialIssueData.RelatedObject);
		}

		// Token: 0x06002DF7 RID: 11767 RVA: 0x000C0F1E File Offset: 0x000BF11E
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000DB5 RID: 3509
		private const IssueBase.IssueFrequency VillageNeedsToolsIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x0200067E RID: 1662
		public class VillageNeedsToolsIssue : IssueBase
		{
			// Token: 0x06005455 RID: 21589 RVA: 0x0017C7AF File Offset: 0x0017A9AF
			internal static void AutoGeneratedStaticCollectObjectsVillageNeedsToolsIssue(object o, List<object> collectedObjects)
			{
				((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06005456 RID: 21590 RVA: 0x0017C7BD File Offset: 0x0017A9BD
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._requestedItem);
				collectedObjects.Add(this._exchangeItem);
			}

			// Token: 0x06005457 RID: 21591 RVA: 0x0017C7DE File Offset: 0x0017A9DE
			internal static object AutoGeneratedGetMemberValue_requestedItem(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue)o)._requestedItem;
			}

			// Token: 0x06005458 RID: 21592 RVA: 0x0017C7EB File Offset: 0x0017A9EB
			internal static object AutoGeneratedGetMemberValue_exchangeItem(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue)o)._exchangeItem;
			}

			// Token: 0x06005459 RID: 21593 RVA: 0x0017C7F8 File Offset: 0x0017A9F8
			internal static object AutoGeneratedGetMemberValue_numberOfExchangeItem(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue)o)._numberOfExchangeItem;
			}

			// Token: 0x0600545A RID: 21594 RVA: 0x0017C80A File Offset: 0x0017AA0A
			internal static object AutoGeneratedGetMemberValue_numberOfRequestedItem(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue)o)._numberOfRequestedItem;
			}

			// Token: 0x0600545B RID: 21595 RVA: 0x0017C81C File Offset: 0x0017AA1C
			internal static object AutoGeneratedGetMemberValue_payment(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue)o)._payment;
			}

			// Token: 0x17001200 RID: 4608
			// (get) Token: 0x0600545C RID: 21596 RVA: 0x0017C82E File Offset: 0x0017AA2E
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Duration;
				}
			}

			// Token: 0x17001201 RID: 4609
			// (get) Token: 0x0600545D RID: 21597 RVA: 0x0017C831 File Offset: 0x0017AA31
			protected override int RewardGold
			{
				get
				{
					return 500 + this._numberOfRequestedItem * (int)((float)(base.IssueSettlement.SettlementComponent.GetItemPrice(this._requestedItem, null, false) + this._requestedItem.Value) / 2f);
				}
			}

			// Token: 0x17001202 RID: 4610
			// (get) Token: 0x0600545E RID: 21598 RVA: 0x0017C86C File Offset: 0x0017AA6C
			private int CostOfToolsForAlternativeSolution
			{
				get
				{
					return (int)((float)(this._requestedItem.Value * this._numberOfRequestedItem) * 0.7f);
				}
			}

			// Token: 0x17001203 RID: 4611
			// (get) Token: 0x0600545F RID: 21599 RVA: 0x0017C888 File Offset: 0x0017AA88
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return 500 + (int)(700f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17001204 RID: 4612
			// (get) Token: 0x06005460 RID: 21600 RVA: 0x0017C89D File Offset: 0x0017AA9D
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=gnuojd9u}{VILLAGE} Needs Tools", null);
					textObject.SetTextVariable("VILLAGE", base.IssueOwner.CurrentSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17001205 RID: 4613
			// (get) Token: 0x06005461 RID: 21601 RVA: 0x0017C8C6 File Offset: 0x0017AAC6
			public override TextObject Description
			{
				get
				{
					return new TextObject("{=Td2RGRBn}Headman in the village requested tools to increase production.", null);
				}
			}

			// Token: 0x17001206 RID: 4614
			// (get) Token: 0x06005462 RID: 21602 RVA: 0x0017C8D3 File Offset: 0x0017AAD3
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					return new TextObject("{=BGJpwxvm}We do have some problems. [ib:demure][if:convo_dismayed] A sickness passed through here last month. Praise the Heavens, only a few people died, but many were weakened and we couldn't get much work done. Now we need to hire some laborers from nearby settlements to make up the shortfall, but we don't have the tools for them. We're in a bit of a rush - do you think you could find tools for us?", null);
				}
			}

			// Token: 0x17001207 RID: 4615
			// (get) Token: 0x06005463 RID: 21603 RVA: 0x0017C8E0 File Offset: 0x0017AAE0
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=3EL0wY1h}Tell me about the details.", null);
				}
			}

			// Token: 0x17001208 RID: 4616
			// (get) Token: 0x06005464 RID: 21604 RVA: 0x0017C8F0 File Offset: 0x0017AAF0
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject;
					if (this._exchangeItem == null)
					{
						textObject = new TextObject("{=daXZlOBi}We need {REQUESTED_ITEM_COUNT} {.%}{?(REQUESTED_ITEM_COUNT > 1)}{PLURAL(REQUESTED_ITEM)}{?}{REQUESTED_ITEM}{\\?}{.%} in {NUMBER_OF_DAYS} days. We can offer {PAYMENT}{GOLD_ICON} for the tools and your services. What do you say?", null);
						textObject.SetTextVariable("PAYMENT", this._payment);
					}
					else
					{
						textObject = new TextObject("{=uwmfgcM3}We need {REQUESTED_ITEM_COUNT} {.%}{?(REQUESTED_ITEM_COUNT > 1)}{PLURAL(REQUESTED_ITEM)}{?}{REQUESTED_ITEM}{\\?}{.%} in {NUMBER_OF_DAYS} days. The village is short on denars so we can make the payment in kind - with {?NUMBER_OF_EXCHANGE_ITEM > 1}{NUMBER_OF_EXCHANGE_ITEM} {._}{PLURAL(EXCHANGE_ITEM)}{?}one {._}{EXCHANGE_ITEM}{\\?}. What do you say?", null);
						textObject.SetTextVariable("EXCHANGE_ITEM", this._exchangeItem.Name);
						textObject.SetTextVariable("NUMBER_OF_EXCHANGE_ITEM", this._numberOfExchangeItem);
					}
					textObject.SetTextVariable("REQUESTED_ITEM", this._requestedItem.Name);
					textObject.SetTextVariable("REQUESTED_ITEM_COUNT", this._numberOfRequestedItem);
					textObject.SetTextVariable("NUMBER_OF_DAYS", 30);
					return textObject;
				}
			}

			// Token: 0x17001209 RID: 4617
			// (get) Token: 0x06005465 RID: 21605 RVA: 0x0017C992 File Offset: 0x0017AB92
			public override TextObject IssuePlayerResponseAfterAlternativeExplanation
			{
				get
				{
					return new TextObject("{=Tp4X51vX}Maybe my men can handle this for you.", null);
				}
			}

			// Token: 0x1700120A RID: 4618
			// (get) Token: 0x06005466 RID: 21606 RVA: 0x0017C9A0 File Offset: 0x0017ABA0
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=8llksa4h}If so, you'll need a man with good understanding of trade. Also you will need at least {NUMBER_OF_TROOPS} fighting men to protect the goods while taking them to market and back. Your companion will also probably need around {GOLD_COST}{GOLD_ICON} in order to buy the tools.[if:convo_confused_normal]", null);
					textObject.SetTextVariable("NUMBER_OF_TROOPS", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("GOLD_COST", this.CostOfToolsForAlternativeSolution);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x1700120B RID: 4619
			// (get) Token: 0x06005467 RID: 21607 RVA: 0x0017C9ED File Offset: 0x0017ABED
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=ggGmjgIS}I think I can handle this myself.", null);
				}
			}

			// Token: 0x1700120C RID: 4620
			// (get) Token: 0x06005468 RID: 21608 RVA: 0x0017C9FA File Offset: 0x0017ABFA
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=5aDpzB1F}My men will deliver your goods on time don't worry.", null);
				}
			}

			// Token: 0x1700120D RID: 4621
			// (get) Token: 0x06005469 RID: 21609 RVA: 0x0017CA07 File Offset: 0x0017AC07
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					return new TextObject("{=bkZOcbGu}Your men are still getting us the tools. I ask for your patience. We very much appreciate this.", null);
				}
			}

			// Token: 0x1700120E RID: 4622
			// (get) Token: 0x0600546A RID: 21610 RVA: 0x0017CA14 File Offset: 0x0017AC14
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x1700120F RID: 4623
			// (get) Token: 0x0600546B RID: 21611 RVA: 0x0017CA17 File Offset: 0x0017AC17
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001210 RID: 4624
			// (get) Token: 0x0600546C RID: 21612 RVA: 0x0017CA1A File Offset: 0x0017AC1A
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 4 + MathF.Ceiling(5f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17001211 RID: 4625
			// (get) Token: 0x0600546D RID: 21613 RVA: 0x0017CA2F File Offset: 0x0017AC2F
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 2 + MathF.Ceiling(4f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17001212 RID: 4626
			// (get) Token: 0x0600546E RID: 21614 RVA: 0x0017CA44 File Offset: 0x0017AC44
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					return new TextObject("{=JxUrkzd1}Thank you. I hope your men can get us the tools on time. Good luck.[ib:demure][if:convo_astonished]", null);
				}
			}

			// Token: 0x17001213 RID: 4627
			// (get) Token: 0x0600546F RID: 21615 RVA: 0x0017CA54 File Offset: 0x0017AC54
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=qycE7IO0}{QUEST_GIVER.LINK} told you that {?QUEST_GIVER.GENDER}she{?}he{\\?} needs {._}{ITEM} for {?QUEST_GIVER.GENDER}her{?}his{\\?} village. {?QUEST_GIVER.GENDER}She{?}He{\\?} offers you {REWARD_GOLD}{GOLD_ICON} for the delivery of the tools. You asked your companion {COMPANION.LINK} and {NEEDED_MEN_COUNT} of your men to deliver {NUMBER_OF_ITEM} {?NUMBER_OF_ITEM>1}units{?}unit{\\?} of {._}{ITEM} to {QUEST_GIVER.LINK}. They will rejoin your party in {ALTERNATIVE_SOLUTION_DURATION} days.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("ITEM", this._requestedItem.Name);
					textObject.SetTextVariable("NUMBER_OF_ITEM", this._numberOfRequestedItem);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("NEEDED_MEN_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("ALTERNATIVE_SOLUTION_DURATION", base.GetTotalAlternativeSolutionDurationInDays());
					return textObject;
				}
			}

			// Token: 0x17001214 RID: 4628
			// (get) Token: 0x06005470 RID: 21616 RVA: 0x0017CB10 File Offset: 0x0017AD10
			public override TextObject IssueAlternativeSolutionSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=W0w0Eunx}Your companion {COMPANION.LINK} has delivered {ISSUE_GIVER.LINK}'s goods as you promised.", null);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x06005471 RID: 21617 RVA: 0x0017CB5C File Offset: 0x0017AD5C
			public VillageNeedsToolsIssue(Hero issueOwner, ItemObject requestedItem) : base(issueOwner, CampaignTime.DaysFromNow(30f))
			{
				this._requestedItem = requestedItem;
				int itemPrice = issueOwner.CurrentSettlement.SettlementComponent.GetItemPrice(this._requestedItem, null, false);
				this._numberOfRequestedItem = MathF.Round((float)((int)(2500f / (float)this._requestedItem.Value)) * base.IssueDifficultyMultiplier);
				int num = 500 + this._numberOfRequestedItem * (int)((float)(itemPrice + this._requestedItem.Value) / 2f);
				if (issueOwner.CurrentSettlement.Village.Hearth < 300f)
				{
					this._exchangeItem = issueOwner.CurrentSettlement.Village.VillageType.PrimaryProduction;
					this._numberOfExchangeItem = MathF.Ceiling((float)num * 0.7f / (float)this._exchangeItem.Value);
					return;
				}
				this._payment = num;
				this._numberOfExchangeItem = 0;
				this._exchangeItem = null;
			}

			// Token: 0x06005472 RID: 21618 RVA: 0x0017CC4B File Offset: 0x0017AE4B
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.VillageHearth)
				{
					return -0.2f;
				}
				return 0f;
			}

			// Token: 0x06005473 RID: 21619 RVA: 0x0017CC60 File Offset: 0x0017AE60
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				return new ValueTuple<SkillObject, int>((hero.GetSkillValue(DefaultSkills.Engineering) >= hero.GetSkillValue(DefaultSkills.Crafting)) ? DefaultSkills.Engineering : DefaultSkills.Crafting, 120);
			}

			// Token: 0x06005474 RID: 21620 RVA: 0x0017CC8D File Offset: 0x0017AE8D
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06005475 RID: 21621 RVA: 0x0017CC8F File Offset: 0x0017AE8F
			protected override void HourlyTick()
			{
			}

			// Token: 0x06005476 RID: 21622 RVA: 0x0017CC91 File Offset: 0x0017AE91
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest(questId, base.IssueOwner, this._requestedItem, this._numberOfRequestedItem, this._exchangeItem, this._numberOfExchangeItem, this._payment, CampaignTime.DaysFromNow(30f));
			}

			// Token: 0x06005477 RID: 21623 RVA: 0x0017CCC7 File Offset: 0x0017AEC7
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x06005478 RID: 21624 RVA: 0x0017CCCC File Offset: 0x0017AECC
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				bool flag2 = issueGiver.GetRelationWithPlayer() >= -10f && !issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction);
				flag = (flag2 ? IssueBase.PreconditionFlags.None : ((!issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction)) ? IssueBase.PreconditionFlags.Relation : IssueBase.PreconditionFlags.AtWar));
				relationHero = issueGiver;
				skill = null;
				return flag2;
			}

			// Token: 0x06005479 RID: 21625 RVA: 0x0017CD30 File Offset: 0x0017AF30
			public override bool IssueStayAliveConditions()
			{
				return base.IssueOwner.CurrentSettlement.ItemRoster.GetItemNumber(this._requestedItem) == 0 && !base.IssueOwner.CurrentSettlement.IsRaided && !base.IssueOwner.CurrentSettlement.IsUnderRaid;
			}

			// Token: 0x0600547A RID: 21626 RVA: 0x0017CD81 File Offset: 0x0017AF81
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x0600547B RID: 21627 RVA: 0x0017CD83 File Offset: 0x0017AF83
			public override void AlternativeSolutionStartConsequence()
			{
				GiveGoldAction.ApplyForCharacterToParty(Hero.MainHero, null, this.CostOfToolsForAlternativeSolution, false);
			}

			// Token: 0x0600547C RID: 21628 RVA: 0x0017CD97 File Offset: 0x0017AF97
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x0600547D RID: 21629 RVA: 0x0017CDAF File Offset: 0x0017AFAF
			public override bool IsTroopTypeNeededByAlternativeSolution(CharacterObject character)
			{
				return character.Tier >= 2;
			}

			// Token: 0x0600547E RID: 21630 RVA: 0x0017CDBD File Offset: 0x0017AFBD
			public override bool AlternativeSolutionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false) && QuestHelper.CheckGoldForAlternativeSolution(this.CostOfToolsForAlternativeSolution, ref explanation);
			}

			// Token: 0x0600547F RID: 21631 RVA: 0x0017CDF0 File Offset: 0x0017AFF0
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest.GiveTradeOrExchangeRewardToMainParty(base.IssueOwner, this._payment, this._exchangeItem, this._numberOfExchangeItem);
				ChangeRelationAction.ApplyPlayerRelation(base.IssueOwner, 5, true, true);
				base.IssueOwner.AddPower(10f);
				base.IssueOwner.CurrentSettlement.Village.Hearth += 50f;
			}

			// Token: 0x04001B59 RID: 7001
			private const int TimeLimit = 30;

			// Token: 0x04001B5A RID: 7002
			private const int TroopTierForAlternativeSolution = 2;

			// Token: 0x04001B5B RID: 7003
			public const int PowerRewardForQuestGiverOnSuccess = 10;

			// Token: 0x04001B5C RID: 7004
			private const int RelationWithIssueOwnerRewardOnSuccess = 5;

			// Token: 0x04001B5D RID: 7005
			private const int VillageHeartChangeOnSuccess = 50;

			// Token: 0x04001B5E RID: 7006
			private const int RequiredSkillValueForAlternativeSolution = 120;

			// Token: 0x04001B5F RID: 7007
			[SaveableField(10)]
			private readonly ItemObject _requestedItem;

			// Token: 0x04001B60 RID: 7008
			[SaveableField(20)]
			private readonly ItemObject _exchangeItem;

			// Token: 0x04001B61 RID: 7009
			[SaveableField(30)]
			private readonly int _numberOfExchangeItem;

			// Token: 0x04001B62 RID: 7010
			[SaveableField(40)]
			private readonly int _numberOfRequestedItem;

			// Token: 0x04001B63 RID: 7011
			[SaveableField(50)]
			private readonly int _payment;
		}

		// Token: 0x0200067F RID: 1663
		public class VillageNeedsToolsIssueQuest : QuestBase
		{
			// Token: 0x06005480 RID: 21632 RVA: 0x0017CE59 File Offset: 0x0017B059
			internal static void AutoGeneratedStaticCollectObjectsVillageNeedsToolsIssueQuest(object o, List<object> collectedObjects)
			{
				((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06005481 RID: 21633 RVA: 0x0017CE67 File Offset: 0x0017B067
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._requestedTradeGood);
				collectedObjects.Add(this._exchangeItem);
				collectedObjects.Add(this._numberOfToolsLog);
			}

			// Token: 0x06005482 RID: 21634 RVA: 0x0017CE94 File Offset: 0x0017B094
			internal static object AutoGeneratedGetMemberValue_requestedTradeGood(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest)o)._requestedTradeGood;
			}

			// Token: 0x06005483 RID: 21635 RVA: 0x0017CEA1 File Offset: 0x0017B0A1
			internal static object AutoGeneratedGetMemberValue_numberOfRequestedGood(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest)o)._numberOfRequestedGood;
			}

			// Token: 0x06005484 RID: 21636 RVA: 0x0017CEB3 File Offset: 0x0017B0B3
			internal static object AutoGeneratedGetMemberValue_exchangeItem(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest)o)._exchangeItem;
			}

			// Token: 0x06005485 RID: 21637 RVA: 0x0017CEC0 File Offset: 0x0017B0C0
			internal static object AutoGeneratedGetMemberValue_numberOfExchangeItem(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest)o)._numberOfExchangeItem;
			}

			// Token: 0x06005486 RID: 21638 RVA: 0x0017CED2 File Offset: 0x0017B0D2
			internal static object AutoGeneratedGetMemberValue_numberOfToolsLog(object o)
			{
				return ((VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest)o)._numberOfToolsLog;
			}

			// Token: 0x17001215 RID: 4629
			// (get) Token: 0x06005487 RID: 21639 RVA: 0x0017CEDF File Offset: 0x0017B0DF
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=gnuojd9u}{VILLAGE} Needs Tools", null);
					textObject.SetTextVariable("VILLAGE", base.QuestGiver.CurrentSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17001216 RID: 4630
			// (get) Token: 0x06005488 RID: 21640 RVA: 0x0017CF08 File Offset: 0x0017B108
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001217 RID: 4631
			// (get) Token: 0x06005489 RID: 21641 RVA: 0x0017CF0C File Offset: 0x0017B10C
			private TextObject QuestStartedLog
			{
				get
				{
					TextObject textObject = new TextObject("{=BOp61V4A}{QUEST_GIVER.LINK} told you that {?QUEST_GIVER.GENDER}she{?}he{\\?} needs {._}{REQUIRED_ITEM} for {?QUEST_GIVER.GENDER}her{?}his{\\?} village. {?QUEST_GIVER.GENDER}She{?}He{\\?} asked you to bring {ITEM_COUNT} {.%}{?(ITEM_COUNT > 1)}{PLURAL(REQUIRED_ITEM)}{?}{REQUIRED_ITEM}{\\?}{.%}  to {?QUEST_GIVER.GENDER}her{?}him{\\?}. {PAYMENT_DESCRIPTION}", null);
					textObject.SetTextVariable("REQUIRED_ITEM", this._requestedTradeGood.Name);
					textObject.SetTextVariable("ITEM_COUNT", this._numberOfRequestedGood);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					TextObject textObject2;
					if (this._exchangeItem == null)
					{
						textObject2 = new TextObject("{=ZOTBiLiS}{?QUEST_GIVER.GENDER}She{?}He{\\?} will pay you {PAYMENT}{GOLD_ICON} when the task is done.", null);
						textObject2.SetTextVariable("PAYMENT", this.RewardGold);
						textObject2.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					}
					else
					{
						textObject2 = new TextObject("{=eQzskygV}{?QUEST_GIVER.GENDER}She{?}He{\\?} will make payment as {EXCHANGE_ITEM_COUNT} {?EXCHANGE_ITEM_COUNT>1}units{?}unit{\\?} of {._}{EXCHANGE_ITEM} when the task is done.", null);
						textObject2.SetTextVariable("EXCHANGE_ITEM", this._exchangeItem.Name);
						textObject2.SetTextVariable("EXCHANGE_ITEM_COUNT", this._numberOfExchangeItem);
					}
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject2, false);
					textObject.SetTextVariable("PAYMENT_DESCRIPTION", textObject2);
					return textObject;
				}
			}

			// Token: 0x17001218 RID: 4632
			// (get) Token: 0x0600548A RID: 21642 RVA: 0x0017CFFC File Offset: 0x0017B1FC
			private TextObject WarDeclaredQuestCancelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=PakhagOy}Your clan is now at war with {QUEST_GIVER.LINK}'s lord. Your agreement with {QUEST_GIVER.LINK} was canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001219 RID: 4633
			// (get) Token: 0x0600548B RID: 21643 RVA: 0x0017D030 File Offset: 0x0017B230
			private TextObject PlayerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700121A RID: 4634
			// (get) Token: 0x0600548C RID: 21644 RVA: 0x0017D064 File Offset: 0x0017B264
			private TextObject VillageRaidedQuestCancelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=9zJNjWes}{SETTLEMENT} was raided. Your agreement with {QUEST_GIVER.LINK} was canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x1700121B RID: 4635
			// (get) Token: 0x0600548D RID: 21645 RVA: 0x0017D0B4 File Offset: 0x0017B2B4
			private TextObject QuestTimeOutFailLog
			{
				get
				{
					TextObject textObject = new TextObject("{=jXTshvhV}You couldn't fully bring {ITEM} to {?QUEST_GIVER.GENDER}her{?}him{\\?} on time.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("ITEM", this._requestedTradeGood.Name);
					return textObject;
				}
			}

			// Token: 0x1700121C RID: 4636
			// (get) Token: 0x0600548E RID: 21646 RVA: 0x0017D100 File Offset: 0x0017B300
			private TextObject QuestSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=ytqqEyFw}You brought {NUMBER_OF_ITEM} {?NUMBER_OF_ITEM>1}units{?}unit{\\?} of {ITEM} to {?QUEST_GIVER.GENDER}her{?}him{\\?} as promised.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("ITEM", this._requestedTradeGood.Name);
					textObject.SetTextVariable("NUMBER_OF_ITEM", this._numberOfRequestedGood);
					return textObject;
				}
			}

			// Token: 0x0600548F RID: 21647 RVA: 0x0017D15B File Offset: 0x0017B35B
			public VillageNeedsToolsIssueQuest(string questId, Hero questGiver, ItemObject requestedItem, int numberOfRequestedGood, ItemObject exchangeItem, int numberOfExchangeItem, int payment, CampaignTime duration) : base(questId, questGiver, duration, payment)
			{
				this._requestedTradeGood = requestedItem;
				this._numberOfRequestedGood = numberOfRequestedGood;
				this._exchangeItem = exchangeItem;
				this._numberOfExchangeItem = numberOfExchangeItem;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06005490 RID: 21648 RVA: 0x0017D194 File Offset: 0x0017B394
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=ELxhTMuy}Excellent. But please hurry - we need to put the men we hired to work right away. Good luck.", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(delegate
				{
					base.StartQuest();
					TextObject textObject = new TextObject("{=M8PXWpyV}Collected {ITEM}", null);
					textObject.SetTextVariable("ITEM", this._requestedTradeGood.Name);
					this._numberOfToolsLog = base.AddDiscreteLog(this.QuestStartedLog, textObject, 0, this._numberOfRequestedGood, null, false);
					this.UpdateToolsAmount();
				}).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=dJVjbgyu}Any news about our tools {?PLAYER.GENDER}madame{?}sir{\\?}?", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).BeginPlayerOptions().PlayerOption(new TextObject("{=yvXNvh2B}Yes, I brought your tools.", null), null).Condition(new ConversationSentence.OnConditionDelegate(this.PlayerHasTools)).NpcLine(new TextObject("{=yF3cBat5}Thank you {?PLAYER.GENDER}madame{?}sir{\\?}. Here is what we promised.", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.FinishQuestSuccess1)).CloseDialog().PlayerOption(new TextObject("{=ULWYVuVw}I'm still looking for your goods.", null), null).NpcLine(new TextObject("{=tkaEZNpB}Of course. But… please hurry, {?PLAYER.GENDER}madame{?}sir{\\?}. We can't afford to pay the hired men to sit around. We don't have much money to spare, {?PLAYER.GENDER}madame{?}sir{\\?}.", null), null, null).CloseDialog().EndPlayerOptions();
			}

			// Token: 0x06005491 RID: 21649 RVA: 0x0017D29D File Offset: 0x0017B49D
			private bool PlayerHasTools()
			{
				return this.GetCurrentToolsAmountInPlayerRoster() >= this._numberOfRequestedGood;
			}

			// Token: 0x06005492 RID: 21650 RVA: 0x0017D2B0 File Offset: 0x0017B4B0
			protected override void HourlyTick()
			{
			}

			// Token: 0x06005493 RID: 21651 RVA: 0x0017D2B4 File Offset: 0x0017B4B4
			protected override void RegisterEvents()
			{
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.RaidCompletedEvent.AddNonSerializedListener(this, new Action<BattleSideEnum, RaidEventComponent>(this.RaidCompleted));
				CampaignEvents.PlayerInventoryExchangeEvent.AddNonSerializedListener(this, new Action<List<ValueTuple<ItemRosterElement, int>>, List<ValueTuple<ItemRosterElement, int>>, bool>(this.OnInventoryExchange));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
			}

			// Token: 0x06005494 RID: 21652 RVA: 0x0017D334 File Offset: 0x0017B534
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x06005495 RID: 21653 RVA: 0x0017D347 File Offset: 0x0017B547
			private void RaidCompleted(BattleSideEnum winnerSide, RaidEventComponent raidEvent)
			{
				if (raidEvent.MapEventSettlement == base.QuestGiver.CurrentSettlement)
				{
					base.CompleteQuestWithCancel(this.VillageRaidedQuestCancelLog);
				}
			}

			// Token: 0x06005496 RID: 21654 RVA: 0x0017D368 File Offset: 0x0017B568
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this.PlayerDeclaredWarQuestLogText, this.WarDeclaredQuestCancelLog, false);
			}

			// Token: 0x06005497 RID: 21655 RVA: 0x0017D380 File Offset: 0x0017B580
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this.WarDeclaredQuestCancelLog);
				}
			}

			// Token: 0x06005498 RID: 21656 RVA: 0x0017D3AF File Offset: 0x0017B5AF
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x06005499 RID: 21657 RVA: 0x0017D3B7 File Offset: 0x0017B5B7
			private void OnInventoryExchange(List<ValueTuple<ItemRosterElement, int>> purchasedItems, List<ValueTuple<ItemRosterElement, int>> soldItems, bool isTrading)
			{
				this.UpdateToolsAmount();
			}

			// Token: 0x0600549A RID: 21658 RVA: 0x0017D3BF File Offset: 0x0017B5BF
			private int GetCurrentToolsAmountInPlayerRoster()
			{
				return MobileParty.MainParty.ItemRoster.GetItemNumber(this._requestedTradeGood);
			}

			// Token: 0x0600549B RID: 21659 RVA: 0x0017D3D6 File Offset: 0x0017B5D6
			private void UpdateToolsAmount()
			{
				this._numberOfToolsLog.UpdateCurrentProgress((int)MathF.Clamp((float)this.GetCurrentToolsAmountInPlayerRoster(), 0f, (float)this._numberOfRequestedGood));
			}

			// Token: 0x0600549C RID: 21660 RVA: 0x0017D3FC File Offset: 0x0017B5FC
			protected override void OnTimedOut()
			{
				base.AddLog(this.QuestTimeOutFailLog, false);
				base.QuestGiver.AddPower(-10f);
				base.QuestGiver.CurrentSettlement.Village.Hearth += -30f;
				ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, -5, true, true);
			}

			// Token: 0x0600549D RID: 21661 RVA: 0x0017D458 File Offset: 0x0017B658
			private void FinishQuestSuccess1()
			{
				base.AddLog(this.QuestSuccessLog, false);
				base.QuestGiver.AddPower(10f);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(Hero.MainHero, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, 30)
				});
				PartyBase.MainParty.ItemRoster.AddToCounts(this._requestedTradeGood, -this._numberOfRequestedGood);
				VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest.GiveTradeOrExchangeRewardToMainParty(base.QuestGiver, this.RewardGold, this._exchangeItem, this._numberOfExchangeItem);
				int num;
				if (this._exchangeItem != null)
				{
					ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, 7, true, true);
					foreach (Hero hero in base.QuestGiver.CurrentSettlement.Notables)
					{
						if (hero != base.QuestGiver)
						{
							ChangeRelationAction.ApplyPlayerRelation(hero, 2, true, true);
						}
					}
					num = 40;
				}
				else
				{
					ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, 5, true, true);
					num = 20;
				}
				base.QuestGiver.CurrentSettlement.Village.Hearth += (float)num;
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x0600549E RID: 21662 RVA: 0x0017D588 File Offset: 0x0017B788
			public static void GiveTradeOrExchangeRewardToMainParty(Hero questGiver, int gold, ItemObject exchangeItem, int exchangeItemCount)
			{
				if (exchangeItem != null)
				{
					questGiver.CurrentSettlement.ItemRoster.AddToCounts(exchangeItem, exchangeItemCount);
					ItemRosterElement itemRosterElement = new ItemRosterElement(exchangeItem, exchangeItemCount, null);
					GiveItemAction.ApplyForParties(questGiver.CurrentSettlement.Party, PartyBase.MainParty, itemRosterElement);
					return;
				}
				GiveGoldAction.ApplyForQuestBetweenCharacters(questGiver, Hero.MainHero, gold, false);
			}

			// Token: 0x04001B64 RID: 7012
			private const int VillageHeartChangeOnExchangeSuccess = 40;

			// Token: 0x04001B65 RID: 7013
			private const int VillageHeartChangeOnTradeSuccess = 20;

			// Token: 0x04001B66 RID: 7014
			private const int TraitChangeOnSuccess = 30;

			// Token: 0x04001B67 RID: 7015
			private const int RelationChangeWithQuestGiverOnExchangeSuccess = 7;

			// Token: 0x04001B68 RID: 7016
			private const int RelationChangeWithNotablesOnExchangeSuccess = 2;

			// Token: 0x04001B69 RID: 7017
			private const int RelationChangeWithQuestGiverOnTradeSuccess = 5;

			// Token: 0x04001B6A RID: 7018
			private const int RelationChangeWithQuestGiverOnFail = -5;

			// Token: 0x04001B6B RID: 7019
			private const int QuestGiverPowerChangeOnFail = -10;

			// Token: 0x04001B6C RID: 7020
			private const int VillageHeartChangeOnFail = -30;

			// Token: 0x04001B6D RID: 7021
			[SaveableField(10)]
			private readonly ItemObject _requestedTradeGood;

			// Token: 0x04001B6E RID: 7022
			[SaveableField(20)]
			private readonly int _numberOfRequestedGood;

			// Token: 0x04001B6F RID: 7023
			[SaveableField(30)]
			private readonly ItemObject _exchangeItem;

			// Token: 0x04001B70 RID: 7024
			[SaveableField(40)]
			private readonly int _numberOfExchangeItem;

			// Token: 0x04001B71 RID: 7025
			[SaveableField(50)]
			private JournalLog _numberOfToolsLog;
		}

		// Token: 0x02000680 RID: 1664
		public class VillageNeedsToolsIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x060054A2 RID: 21666 RVA: 0x0017D653 File Offset: 0x0017B853
			public VillageNeedsToolsIssueTypeDefiner() : base(600000)
			{
			}

			// Token: 0x060054A3 RID: 21667 RVA: 0x0017D660 File Offset: 0x0017B860
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssue), 1, null);
				base.AddClassDefinition(typeof(VillageNeedsToolsIssueBehavior.VillageNeedsToolsIssueQuest), 2, null);
			}
		}
	}
}
